<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="begin">开启定时器</button>
    <button class="stop">停止定时器</button>

    <script>
        //停止定时器 window.clearInerval(intervalID)
        var begin = document.querySelector('.begin');
        var stop = document.querySelector('.stop');
        var kaishi = null;
        begin.addEventListener('click',function(){ 
          kaishi = setInterval(function(){
                        console.log(1111);
                    },1000)
        })
        stop.addEventListener('click',function(){
            clearInterval(kaishi);
        })
    </script>
</body>
</html>